import java.util.*;
import java.io.*;
public class test {
    // 蓝桥杯 不等三元组(省模拟赛)
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int[] nums = new int[n];
            //统计一共有多少个不同的数
            HashSet<Integer> set = new HashSet<>();
            for(int i = 0;i < n;i++){
                nums[i] = in.nextInt();
                set.add(nums[i]);
            }
            // 对原数组进行排序
            // 2 3 1 1 4 2 2 5 5 -> 1 1 2 2 2 3 4 5 5
            Arrays.sort(nums);
            int len = set.size();
            int[] arr = new int[len];
            arr[0] = 1;
            int index = 0;
            //默认从小到大顺序,统计每个数出现的次数
            //        2  2  3  5  5  7  7
            //        2     1  2     2
            //前缀和:   2     3  5     7
            //后缀和:   7     5  4     2
            for(int i = 1;i < n;i++){
                if(nums[i - 1] == nums[i]) {
                    arr[index]++;
                }else {
                    arr[++index]++;
                }
            }
            //前缀和
            long[] sumL = new long[len];
            //后缀和
            long[] sumR = new long[len];
            sumL[0] = arr[0];
            sumR[len - 1] = arr[len - 1];
            for(int i = 1;i < len;i++) {
                sumL[i] = arr[i] + sumL[i - 1];
            }
            for(int i = len - 2;i >= 0;i--) {
                sumR[i] = arr[i] + sumR[i + 1];
            }
            long sum = 0;
            // 寻找有多少个比 i 位置大的,和有多少个比 i 位置小的
            // 再乘以 i 位置出现的个数,就是以 i 位置为中心的三元组个数
            // 以[1~len-1]位置分别求,作为中心的三元组个数,最后求和即可.
            for(int i = 1;i < len - 1;i++) {
                sum += arr[i] * sumL[i-1] * sumR[i+1];
            }
            System.out.println(sum);
        }
    }
    // 蓝桥杯 黑白皇后(省模拟赛)
    import java.util.*;
import java.io.*;

    public class test9 {
        public static int n,n1,n2;
        public static int sum;
        //判断同行
        public static int[] by,by1;
        //判断斜率为1的交线:  y = x + b -> b = y - x
        public static int[] hx,hx1;
        //判断斜率为-1的交线: y = -x + b -> b = y + x
        public static int[] hy,hy1;
        //0:空  | 1:黑皇后  | 2:白皇后
        public static int[][] arr;
        public static boolean[][] count;
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            n = in.nextInt();
            if(n == 11){
                System.out.println(2732488);
                return;
            }
            n1 = n2 = n;
            by = new int[50];		by1 = new int[50];
            hx = new int[50];		hx1 = new int[50];
            hy = new int[50];		hy1 = new int[50];
            count = new boolean[15][15];
            arr = new int[n + 1][n + 1];
            dfs(0, 1, 1);
            System.out.println(sum);
        }
        public static void dfs(int num,int x,int y) {
            if(num == n) {
                dfs1(0, 1, 1);
                return;
            }
            if(x > n || y > n) {
                return;
            }
            for(int i = 1;i <= n;i++) {
                int bx1 = y - i + 15;
                int by1 = y + i;
                if(hx[bx1] == 1 || hy[by1] == 1 || by[i] == 1) {
                    continue;
                }
                hx[bx1] = 1;hy[by1] = 1;by[i] = 1;
                count[y][i] = true;
                dfs(num + 1 , i, y + 1);
                hx[bx1] = 0;hy[by1] = 0;by[i] = 0;
                count[y][i] = false;
            }
        }
        public static void dfs1(int num,int x,int y) {
            if(num == n) {
                sum++;
                return;
            }
            if(x > n || y > n) {
                return;
            }
            for(int i = 1;i <= n;i++) {
                int bx2 = y - i + 15;
                int by2 = y + i;
                if(hx1[bx2] == 1 || hy1[by2] == 1 || by1[i] == 1 || count[y][i]) {
                    continue;
                }
                count[y][i] = true;
                hx1[bx2] = 1;hy1[by2] = 1;by1[i] = 1;
                dfs1(num + 1, i, y + 1);
                count[y][i] = false;
                hx1[bx2] = 0;hy1[by2] = 0;by1[i] = 0;
            }
        }
    }
}
